home *** CD-ROM | disk | FTP | other *** search
- /* write.c --- 508 */
- #include <stdio.h>
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <fcntl.h>
- #include <io.h>
- /* Initialize array with a string plus Control_Z to
- * mark end of file. */
- static char bigbuffer[60000]="Testing write\n\032";
- main()
- {
- int bytes_written;
- int filehandle;
- char filename[81];
- printf("Enter name of file to be opened for writing:");
- gets(filename);
- /* Open the file for write operations.
- * Don't overwrite existing file. */
- if ((filehandle = open(filename,
- O_WRONLY | O_CREAT | O_EXCL, S_IREAD | S_IWRITE)) == -1)
- {
- perror("Open failed! ");
- exit(1);
- }
- /* Now write out 60,000 bytes of data.
- * Most of it'll be junk. */
- if((bytes_written = write(filehandle, bigbuffer, 60000)) == -1)
- perror("write failed");
- else
- {
- printf("%u bytes written to file: %s\n",
- bytes_written, filename);
- printf("Use 'TYPE %s' to see result\n", filename);
- }
- }